﻿using EF.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EF.Controllers
{
    public class ProductController : Controller
    {
        EShopV10 db = new EShopV10();
        public ActionResult SearchByCategory(int Id)
        {
            var category = db.Categories.Find(Id);
            var model = category.Products;
            return View("ProductList", model);
        }

        public ActionResult Detail(int Id)
        {
            var model = db.Products.Find(Id);
            return View("ProductDetail", model);
        }

        public ActionResult Search()
        {
            var model = db.Products;
            return View(model);
        }

        [HttpPost]
        public ActionResult Search(String Name, double Min, double Max)
        {
            var model = db.Products
                .Where(p=>p.Name.Contains(Name) 
                    && p.UnitPrice >= Min && p.UnitPrice <= Max);
            return View(model);
        }
	}
}